{% extends "parent.html" %}
{% block body %}
<table class="layui-hide" id="test" lay-filter="test"></table>
{% endblock %}

{% block scriptFooter %}
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">一件领取任务</button>
  </div>
</script>
<script>
  layui.use('table', function () {
    var table = layui.table;
    table.render({
      elem: '#test',
      url: '/getCanDoTask',
      toolbar: '#toolbarDemo',
      title: '用户数据表',
      totalRow: true,
      cols: [[
        { type: 'checkbox', fixed: 'left' },
        { field: 'id', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计' },
        { field: 'remark', title: '任务类型', width: 100, },
        { field: 'price', title: '价格' },
        { field: 'status', title: '任务状态' },
        { field: 'media_name', title: '任务平台' },
      ]]
    });
    //工具栏事件
    table.on('toolbar(test)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      if (obj.event === "getCheckData") {
        var ids = []
        checkStatus.data.forEach(item => {
          ids.push(item.id)
        })
        $.ajax({
          url: "/getTask",
          type: 'POST',
          data: JSON.stringify(ids),
          dataType: 'json',
          contentType: 'application/json',
          success: function (data, status, xhr) {
          },
          error: function (xhr, error, exception) {
          }
        });
        layer.msg('领取成功');
      }
    });
  });
</script>
{% endblock %}